package com.bwie.bargain.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.bargain.entity.NotesEntity;
import com.bwie.bargain.service.NotesService;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.R;



/**
 * 
 *
 * @author ShuangzhiZhao
 * @email 466505908@qq.com
 * @date 2022-03-07 19:58:55
 */
@RestController
@RequestMapping("bargain/notes")
public class NotesController {
    @Autowired
    private NotesService notesService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = notesService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
     * findCount  根据用户id和活动id 查找用户参与的次数
     */
    @RequestMapping("/findCount")
    public int findCount(@RequestParam("userId")Long userId,
                       @RequestParam("bargainId")Long bargainId){
        return notesService.findCount(userId,bargainId);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{nid}")
    public R info(@PathVariable("nid") Long nid){
		NotesEntity notes = notesService.getById(nid);

        return R.ok().put("notes", notes);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody NotesEntity notes){
		notesService.save(notes);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody NotesEntity notes){
		notesService.updateById(notes);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] nids){
		notesService.removeByIds(Arrays.asList(nids));

        return R.ok();
    }

}
